#!/bin/sh

#  2 windspeed
#  4 rainfall
#  6 windvane
#  7 humidity
#  8 temperature
# 12 Light

#todo: get args

rm -f *.tmp

while read line; do
    s=$(echo $line|tr -d "|");
    date=$(echo $s|cut -d " " -f1);
    time=$(echo $s|cut -d " " -f2);
    valid=$(echo $s|cut -d " " -f3);
    value=$(echo $s|cut -d " " -f4);
    echo "$date $time $value" >> ${valid}.tmp;
done

rm -f plotdata.txt

let cnt=1;
for f in *.tmp; do
    echo "# dataset $cnt (file $f)" >> plotdata.txt;
    cat $f >> plotdata.txt;
    echo >> plotdata.txt;
    echo >> plotdata.txt;
    let cnt=$cnt+1;
done
rm -f *.tmp
